/**
* coder  : dzlua
* email  : 505544956@qq.com
* module : ApiMgr-client
* path   : src
* file   : auth.js
* time   : 2017-11-20 17:29:14
*/

function logined () {
  let user = JSON.parse(window.localStorage.getItem('user'))
  if (!user) return false
  return true
}

function accessToken () {
  let user = JSON.parse(window.localStorage.getItem('user'))
  if (!user) return null
  return user.access_token
}

function refreshToken () {
  let user = JSON.parse(window.localStorage.getItem('user'))
  if (!user) return null
  return user.refresh_token
}

function saveLogin (loginInfo) {
  let userstr = JSON.stringify(loginInfo)
  window.localStorage.setItem('user', userstr)
}

function removeLogin () {
  window.localStorage.setItem('user', null)
}

export default {
  saveLogin: saveLogin,
  removeLogin: removeLogin,
  logined: logined,
  accessToken: accessToken,
  refreshToken: refreshToken
}
